package 集合;

import 排序算法.测试.TimeUtil;
import java.util.ArrayList;

public class TestSet {
    public static void main(String[] args) {
        ArrayList<String> words = new ArrayList<>();
        FileOperation.readFile("动态数组\\a-tale-of-two-cities.txt",words);

        testTreeSet(words);//O(logn)
        testLinkedSet(words);//O(n^2)
        testArrayList(words);//O(n^3)

    }

    private static void testLinkedSet(ArrayList<String> words) {
        TimeUtil time = new TimeUtil();
        LinkedSet<String> list = new LinkedSet<>();
        time.start();
        for (String word : words) {
            list.add(word);
        }
        time.stop();
        time.show();
        System.out.println("LinkedSet--Size：" + list.size());
    }

    private static void testArrayList(ArrayList<String> words) {
        TimeUtil time = new TimeUtil();
        动态数组.线性表.ArrayList<String> list = new 动态数组.线性表.ArrayList<>();
        for (String word : words) {
            list.add(word);
        }
        time.start();
        for (int i = 0; i < list.size(); i++) {
            for (int j = i + 1; j < list.size(); j++){
                if (list.get(i).equals(list.get(j))){
                    list.remove(j);
                    j--;
                }
            }
            
        }
        time.stop();
        time.show();
        System.out.println("ArrayList--Size：" + list.size());

    }

    private static void testTreeSet(ArrayList<String> words) {
        TimeUtil time = new TimeUtil();
        TreeSet<String> treeSet = new TreeSet<>();
        time.start();
        for (String word : words) {
            treeSet.add(word);
        }
        time.stop();
        time.show();
        System.out.println("TreeSet--Size：" + treeSet.size());
    }
}
